package com.bo.sina.send;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class SendGetMessage {
	public WeiboResponse send(String url,String code) throws IOException {
		HttpURLConnection con=null;
		try{
			 String sCurrentLine;  

			 StringBuffer sTotalString = new StringBuffer("");  

			 sCurrentLine="";  

			 InputStream l_urlStream;  
			 //cityMsg=java.net.URLEncoder.encode(cityMsg, "UTF-8");
			 URL l_url = new URL(url);  

			 con = (HttpURLConnection) l_url.openConnection();
//             con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");   
//             con.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//             con.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
//             con.setRequestProperty("Accept-Language", "zh-cn,zh;q=0.5");
//             con.setRequestProperty("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");
			 int state=con.getResponseCode();
			 if(state==200){
			 con.connect();  

			 l_urlStream = con.getInputStream();  

			 BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream,code));  

			 //得到返回的信息
			 while ((sCurrentLine = l_reader.readLine()) != null) {  
			  sTotalString.append(sCurrentLine); 
			  sTotalString.append("\n");
			 }  
			 l_reader.close();
			 return  new WeiboResponse(con.getHeaderFields().get("Set-Cookie"),sTotalString.toString());
			 }
			 
		}finally{
			con.disconnect();
		}
		return null;
	}
}
